package cn.com.se.网络.websocket_netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @description: TODO
 * @author lingheng
 * @date 2025/4/27 16:12
 * @version 1.0
 */
public class WebSocketServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) {
        ch.pipeline().addLast(new HttpServerCodec()); // HTTP 编解码器
        ch.pipeline().addLast(new HttpObjectAggregator(65536)); // 聚合 HTTP 消息
        ch.pipeline().addLast(new ChunkedWriteHandler()); // 支持大数据流
        ch.pipeline().addLast(new WebSocketServerHandler()); // 自定义 WebSocket 处理器
    }
}
